//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media.Media3D;

namespace OpenLS.Chart.UI
{
    sealed class CubeGeometryFactory : MeshGeometryFactory
    {
        public CubeGeometryFactory(BarDirection direction): base (direction)
        { 
        }

        public override MeshGeometry3D CreateGeometry(Bounds3D bounds, Bounds totalValueBounds2, double floor)
        {
            Bounds boundsX = bounds.X;
            Bounds boundsY = bounds.Y;
            Bounds boundsZ = bounds.Z;
            var result = new MeshGeometry3D();
            {
                Tessellator.Tessellate(
                    result, new Vector3D(0, 0, 1),
                                       new Point3D(boundsX.Low, boundsY.Low, boundsZ.High),
                                       new Point3D(boundsX.High, boundsY.Low, boundsZ.High),
                                       new Point3D(boundsX.High, boundsY.High, boundsZ.High),
                                       new Point3D(boundsX.Low, boundsY.High, boundsZ.High));
                Tessellator.Tessellate(result, new Vector3D(0, 0, -1),
                                       new Point3D(boundsX.Low, boundsY.Low, boundsZ.Low),
                                       new Point3D(boundsX.Low, boundsY.High, boundsZ.Low),
                                       new Point3D(boundsX.High, boundsY.High, boundsZ.Low),
                                       new Point3D(boundsX.High, boundsY.Low, boundsZ.Low));
                Tessellator.Tessellate(result, new Vector3D(0, 1, 0),
                       new Point3D(boundsX.Low, boundsY.High, boundsZ.High),
                       new Point3D(boundsX.High, boundsY.High, boundsZ.High),
                       new Point3D(boundsX.High, boundsY.High, boundsZ.Low),
                       new Point3D(boundsX.Low, boundsY.High, boundsZ.Low));
                Tessellator.Tessellate(result, new Vector3D(0, -1, 0),
                       new Point3D(boundsX.Low, boundsY.Low, boundsZ.High),
                       new Point3D(boundsX.Low, boundsY.Low, boundsZ.Low),
                       new Point3D(boundsX.High, boundsY.Low, boundsZ.Low),
                       new Point3D(boundsX.High, boundsY.Low, boundsZ.High));
                Tessellator.Tessellate(result, new Vector3D(1, 0, 0),
                       new Point3D(boundsX.High, boundsY.Low, boundsZ.High),
                       new Point3D(boundsX.High, boundsY.Low, boundsZ.Low),
                       new Point3D(boundsX.High, boundsY.High, boundsZ.Low),
                       new Point3D(boundsX.High, boundsY.High, boundsZ.High));
                Tessellator.Tessellate(result, new Vector3D(-1, 0, 0),
                       new Point3D(boundsX.Low, boundsY.Low, boundsZ.High),
                       new Point3D(boundsX.Low, boundsY.High, boundsZ.High),
                       new Point3D(boundsX.Low, boundsY.High, boundsZ.Low),
                       new Point3D(boundsX.Low, boundsY.Low, boundsZ.Low));
            }
            result.Freeze();
            return result;
        }
    }
}
